package com.common.app.data.api

import com.common.app.data.bean.KeyPre
import com.common.base.utils.SpUtilsManagement
import com.common.base.app.extras.no
import com.common.base.app.extras.otherwise
import com.common.base.utils.DebugUtils
import rxhttp.wrapper.annotation.DefaultDomain

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/8/19
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
object ApiConstant {

    @JvmField
    @DefaultDomain
    val baseUrl = getBaseUrl()

    //接口请求地址
    private const val API_URL = "https://ocellhealth-server-test.graysharks.com/"//线上生产
    private const val API_URL_TEST = "https://ocellhealth-server-test.graysharks.com/"//测试环境
    private const val API_URL_DEV = "http://10.0.18.70:8086/"//本地环境
    private const val API_URL_DEV2 = "http://10.0.18.70:8087/"//本地环境

    /**
     * 服务协议地址
     */
    const val SERVICE_AGREEMENT_SERVER = "https://www.faxian.ink/?page_id=1869"

    /**
     * 隐私政策地址
     */
    const val PRIVACY_POLICY_SERVER = "https://www.faxian.ink/?page_id=1856"

    //客服聊天
    const val CUSTOMER_SERVICE_CHAT = "https://webchat-sh.clink.cn/chat.html?"

    //H5地址
    var CONFIG_HTML_HOST:String? = "https://store.blackshark.com/m/index.html#/"

    //备案信息查询
    var CONFIG_BEIAN_HTML:String? = "https://beian.miit.gov.cn"

    //如果后缀不带/  自动加上
    private fun checkUrl(url: String): String {
        url.endsWith("/").no { return "$url/" }.otherwise { return url }
    }

    fun getBaseUrl(): String {
        return checkUrl(
            when {
                DebugUtils.isTestModel() -> API_URL_TEST
                DebugUtils.isDevModel() -> API_URL_DEV
                DebugUtils.isDevModel2() -> API_URL_DEV2
                else -> API_URL
            }
        )
    }

    fun getBsAccountId(): String {
        return when {
            DebugUtils.isTestModel() -> "797894409"
            DebugUtils.isDevModel() -> "7698493955"
            else -> "6561961784"
        }
    }

    fun getBsAccountCallBackHost(): String {
        return when {
            DebugUtils.isTestModel() -> "https://t-passport.blackshark.com/"
            DebugUtils.isDevModel() -> "https://u-passport.blackshark.com/"
            else -> "https://passport.blackshark.com/"
        }
    }


    fun getBsUpLoadHost(): String {
        return when {
            DebugUtils.isTestModel() -> "https://scsdk.blackshark.com/sa?project=default"
            DebugUtils.isDevModel() -> "https://scsdk.blackshark.com/sa?project=default"
            else -> "https://scsdk.blackshark.com/sa?project=production"
        }
    }

    fun getH5Url(): String {
        return if (CONFIG_HTML_HOST.isNullOrEmpty()) SpUtilsManagement.getString(KeyPre.CONFIG_HTML_HOST, "").also {CONFIG_HTML_HOST = it} else CONFIG_HTML_HOST!!
    }

    //下载app
    fun downloadApp() = getBaseUrl() + "download"

}